{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ad9edbef7097e8d5",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "### 练习题 1: 变量与数据类型操作\n",
    "**题目：**  \n",
    "编写一个程序，要求用户输入一个整数和一个浮点数，然后计算它们的和、差、积和商，并输出结果。确保程序能够处理用户输入的错误。\n",
    "\n",
    "**提示：**\n",
    "- 使用`try-except`块处理用户输入错误。\n",
    "- 使用基本算术操作符进行计算。\n",
    "\n",
    "```python\n",
    "# 示例输入:\n",
    "# 输入整数: 10\n",
    "# 输入浮点数: 3.5\n",
    "# 示例输出:\n",
    "# 和: 13.5\n",
    "# 差: 6.5\n",
    "# 积: 35.0\n",
    "# 商: 2.857142857142857\n",
    "```\n",
    "\n",
    "### 练习题 2: 列表与字典操作\n",
    "**题目：**  \n",
    "给定一个包含学生姓名及其分数的列表，请编写一个程序，将这些信息存储在字典中。然后通过循环遍历字典，输出每个学生的姓名及其对应的分数，并计算和输出平均分。\n",
    "\n",
    "**提示：**\n",
    "- 使用字典存储学生及其分数。\n",
    "- 使用`for`循环遍历字典项。\n",
    "- 计算分数的平均值。\n",
    "\n",
    "```python\n",
    "# 示例输入:\n",
    "# students = {\"Alice\": 85, \"Bob\": 90, \"Charlie\": 78}\n",
    "# 示例输出:\n",
    "# Alice的分数是: 85\n",
    "# Bob的分数是: 90\n",
    "# Charlie的分数是: 78\n",
    "# 平均分是: 84.33\n",
    "```\n",
    "\n",
    "### 练习题 3: 函数与模块操作\n",
    "**题目：**  \n",
    "编写一个函数`calculate_circle_area(radius)`，计算并返回圆的面积。要求用户输入圆的半径，通过调用该函数计算并输出面积。如果用户输入的半径不是有效的数字，程序应捕获并处理异常。\n",
    "\n",
    "**提示：**\n",
    "- 使用`math`模块中的`pi`常量。\n",
    "- 使用`try-except`块处理输入错误。\n",
    "- 圆的面积公式：`area = π * radius^2`。\n",
    "\n",
    "```python\n",
    "# 示例输入:\n",
    "# 输入圆的半径: 5\n",
    "# 示例输出:\n",
    "# 圆的面积是: 78.54\n",
    "```\n",
    "\n",
    "### 练习题 4: 类与对象\n",
    "**题目：**  \n",
    "创建一个名为`BankAccount`的类，具有属性`owner`（账户所有者姓名）和`balance`（账户余额），并包含以下方法：\n",
    "- `deposit(amount)`：存款，将`amount`添加到余额中。\n",
    "- `withdraw(amount)`：取款，从余额中减去`amount`，如果余额不足则提示用户。\n",
    "\n",
    "创建一个`BankAccount`对象，进行一些存款和取款操作，并输出最终余额。\n",
    "\n",
    "**提示：**\n",
    "- 在`withdraw`方法中使用条件判断处理余额不足的情况。\n",
    "\n",
    "```python\n",
    "# 示例输出:\n",
    "# 账户所有者: Alice\n",
    "# 初始余额: 1000\n",
    "# 存款100后的余额: 1100\n",
    "# 取款500后的余额: 600\n",
    "# 尝试取款700: 余额不足，取款失败。\n",
    "# 最终余额: 600\n",
    "```\n",
    "\n",
    "### 练习题 5: 异常处理与文件操作\n",
    "**题目：**  \n",
    "编写一个程序，要求用户输入一个文件名和一个字符串，程序将字符串写入指定文件中。如果文件不存在，程序应创建该文件。然后读取文件内容并输出，最后输出文件的行数。如果在操作文件时出现错误，程序应捕获并处理异常。\n",
    "\n",
    "**提示：**\n",
    "- 使用`with open()`进行文件操作。\n",
    "- 使用`try-except`块处理文件操作中的异常。\n",
    "\n",
    "```python\n",
    "# 示例输入:\n",
    "# 输入文件名: example.txt\n",
    "# 输入要写入的字符串: Hello, Python!\n",
    "# 示例输出:\n",
    "# 文件内容:\n",
    "# Hello, Python!\n",
    "# 文件包含的行数: 1\n",
    "```\n",
    "\n",
    "### 练习题 6: 综合练习：银行账户管理系统\n",
    "**题目：**  \n",
    "结合之前练习的知识点，创建一个简单的银行账户管理系统。该系统应允许用户：\n",
    "1. 创建账户\n",
    "2. 存款\n",
    "3. 取款\n",
    "4. 查询余额\n",
    "\n",
    "使用字典存储多个账户，账户名作为键，`BankAccount`对象作为值。系统应通过循环提供菜单选项，让用户选择要执行的操作，并捕获用户输入的错误。\n",
    "\n",
    "**提示：**\n",
    "- 使用字典管理多个账户。\n",
    "- 使用`while`循环实现菜单操作。\n",
    "- 使用`input()`获取用户输入，并使用条件语句执行相应操作。\n",
    "\n",
    "```python\n",
    "# 示例输出:\n",
    "# 选择操作:\n",
    "# 1. 创建账户\n",
    "# 2. 存款\n",
    "# 3. 取款\n",
    "# 4. 查询余额\n",
    "# 5. 退出\n",
    "# 选择: 1\n",
    "# 输入账户名称: Alice\n",
    "# 输入初始存款: 1000\n",
    "# 账户Alice创建成功，当前余额: 1000\n",
    "\n",
    "# 选择操作:\n",
    "# 2. 存款\n",
    "# 输入账户名称: Alice\n",
    "# 输入存款金额: 500\n",
    "# 存款成功，当前余额: 1500\n",
    "\n",
    "# 选择操作:\n",
    "# 5. 退出\n",
    "# 系统已退出。\n",
    "```\n",
    "\n",
    "---\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "798d0307e93405b1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
